package com.ad.pet.app.type;

import android.app.Activity;

import com.ad.pet.api.ApiService;
import com.ad.pet.app.RxDisposable;
import com.ad.pet.common.data.http.AppSubscriber;
import com.ad.pet.common.data.injector.PerActivity;
import com.ad.pet.common.structure.mvp.AbsBasePresenter;
import com.ad.pet.models.remote.CommList;
import com.ad.pet.models.remote.type.FirstCategroy;

import java.util.List;

import javax.inject.Inject;

/**
 * Created by SEELE on 2018/8/2.
 */
@PerActivity
public class TypePresenter extends AbsBasePresenter implements TypeConstact.Presenter {
    private ApiService mApiService;
    private TypeConstact.View mView;

    private Activity mActivity;

    private RxDisposable mRxDisposable;
    @Inject
    public TypePresenter(ApiService apiService,
                            Activity activity, RxDisposable rxDisposable) {
        mApiService = apiService;
        mActivity = activity;
        mRxDisposable = rxDisposable;
    }
    @Override
    public void onCreate(TypeConstact.View view) {
        this.mView = view;
    }

    @Override
    public void onDestroy() {
        if (mRxDisposable!=null)
            mRxDisposable.clear();
        if (mActivity != null) mActivity = null;
        mView = null;
    }

    @Override
    public void getCatoryList() {
        mRxDisposable.add(mApiService.type_category_list()
                .subscribe(new AppSubscriber<CommList<List<FirstCategroy>>>(mView) {
                    @Override
                    public void next(CommList<List<FirstCategroy>> list) {
                        mView.getCatoryListSuccess(list.getList());
                    }
                }));
    }
}
